package edu.ucsc.mit2008.swan.editor.core.utils;

import java.net.URL;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.resource.ImageDescriptor;

import edu.ucsc.mit2008.swan.editor.core.SwanCorePlugin;

/**
 * Plugin Resource Utils
 * 
 * @author Thushara Sanjeewa Ramasinghe
 */
public class ResourceUtils {
	/**
	 * 
	 * Creates an Image Descriptor from the given bundle resources
	 * 
	 * @param bundle
	 * @param path
	 * @param useMissingImageDescriptor
	 * @return
	 */
	public static ImageDescriptor createImageDescriptor(IPath path, boolean useMissingImageDescriptor) {
		URL url = FileLocator.find(SwanCorePlugin.getDefault().getBundle(), path, null);
		if (url != null) {
			return ImageDescriptor.createFromURL(url);
		}
		if (useMissingImageDescriptor) {
			return ImageDescriptor.getMissingImageDescriptor();
		}
		return null;
	}
}
